package cn.kgc.novel.controller;


import cn.kgc.novel.common.Result;
import cn.kgc.novel.pojo.Message;
import cn.kgc.novel.pojo.Type;
import cn.kgc.novel.service.MessageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import javafx.scene.chart.ValueAxis;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
public class MessageController {

    @Resource
    private MessageService messageService;

    //查找公告
    @GetMapping(value = "/findMessage")
    public Result findMessage(String title,
                              @RequestParam(defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Message> messageList = messageService.findMessage(title);
        PageInfo<Message> pageInfo=new PageInfo<Message>(messageList);
        return Result.ok(pageInfo);
    }
    //添加公告
    //添加公告
    @PostMapping(value = "/addMessage")
    public Result addMessage(@RequestBody Message message,String messageName){
        message.setPresenter(messageName);
        System.out.println("message:"+message);
        messageService.addMessage(message);
        return Result.ok();
    }
    //回显公告
    @GetMapping(value = "/echoMessage")
    public Result echoMessage(Integer mid){
        Message message = messageService.echoMessage(mid);
        return Result.ok(message);
    }
    //修改公告
    @PostMapping(value = "/updateMessage")
    public Result updateMessage(@RequestBody Message message){
        messageService.updateMessage(message);
        return Result.ok();
    }

    //删除公告
    @PostMapping(value = "/deleteMessage")
    public Result deleteMessage(Integer mid ){
        messageService.deleteMessage(mid);
        return Result.ok();
    }

}
